#include "main/utils.h"
using namespace std;

vector<int> sort(const vector<int> &arr1, const vector<int> &arr2) {
  vector<int> ret;
  map<int, int> help_map;
  for (auto ele : arr1) {
    help_map[ele]++;
  }
  for (auto ele : arr2) {
    ret.insert(ret.end(), help_map[ele], ele);
    help_map.erase(ele);
  }
  for (auto ele : help_map) {
    ret.insert(ret.end(), ele.second, ele.first);
  }
  return ret;
}

int main() {
  vector<int> arr1 = {2, 3, 3, 7, 3, 9, 2, 1, 7, 2};
  vector<int> arr2 = {3, 2, 1};
  auto ret = sort(arr1, arr2);
  printVec("o75", ret);

  return 0;
}
